#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "stu_mis.h"
void stu_del()
{
	struct student s;
	int num;

	while (1)
	{
		printf("请输入要删除的学生的学号：");
		if (1 == scanf("%d", &num))
		{
			if (num < STU_NUM_MIN || num > STU_NUM_MAX)
			{
				printf("输入范围错误，请从新输入！\n");
				continue;
			}
			break;
		}
		printf("输入错误，请从新输入！\n");
		fflush(stdin); // 刷新输入缓冲区
	}

	FILE* fp = fopen("student_info.txt", "r+");
	while (fread(&s, sizeof(s), 1, fp) == 1)
	{
		if (s.num == num)
		{
			s.grades = 0;
			*s.name = 0;
			s.num = 0;
			*s.sex = 0;

			while(fseek(fp, -sizeof(s), SEEK_CUR) == 0)
			{
				fwrite(&s, sizeof(s), 1, fp);
				fclose(fp);
				printf("delete seccess\n");
				return;
			}   
		}

		
	}
	return;
}
